package com.hurl.stock.base;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.hibernate.util.ConfigHelper;

import com.hurl.stock.exception.StockServerRuntimeException;
import com.hurl.stock.util.Constants;

public class StockServerCfg {
	private static Properties props = buildConfiguration();
	
	private static Object getObject(String key){
		return props.get(key);
	}
	
	private static int getInt(String key){
		Object value = getObject(key);
		if(value==null){
			return 0;
		}
		return Integer.parseInt(String.valueOf(value));
	}
	
	public static int getHttpClientTimeOut(){
		return getInt(Constants.STOCKSERVER_CFG_HTTPCLIENT_TIMEOUT);
	}
	
	private static Properties buildConfiguration(){
		Properties props = new Properties();
		InputStream is = ConfigHelper.getResourceAsStream( "/"+Constants.STOCKSERVER_CFG_FILE );
		try {
			props.load(is);
		} catch (IOException e) {
			e.printStackTrace();
			throw new StockServerRuntimeException(e.getMessage(),e);
		}
		return props;
	}
	
	
}
